1. Field of the Invention
The present invention relates to image processing methods and apparatuses and, in particular, to methods and apparatuses for image contrast stretching.
2. Description of the Prior Art
Image contrast stretching refers to extending the gray scales of an image to the maximum extent of a monitor. Taking a monitor capable of showing eight-bit gray scales as an example, the 256 gray scales are usually represented as gray scale 0 to gray scale 255. Generally, since image signals lose part of the gray scales due to signal degradation or noise disturbance or so on, the number of gray scales received at the monitor is usually smaller than 256. The object of image contrast stretching is to increase the distribution of gray scales of an image, and thereby enhance the contrast and quality of the image.
Please refer to FIG. 1, which illustrates the block diagram of an apparatus for image contrast stretching in prior arts. The apparatus 10 includes three blocks: a statistic module 11, a gain generating module 12, and a contrast enhancing module 13. The statistic module 11 further includes a first statistic unit 11A, a second statistic unit 11B, and a third statistic unit 11C.
A colored image includes red, green, and blue pixels. The first statistic unit 11A, the second statistic unit 11B, and the third statistic unit 11C are respectively used to statistically calculate the distribution of the gray scales of the red, green, and blue pixels in an input image. The statistic results are depicted as the histograms shown in FIG. 2. FIG. 2(A)˜2(C) respectively show the distributions of the gray scales of the red, green, and blue pixels in an image. In each histogram, the horizontal axis indicates gray scale values (ranging from 0 to 256), and the vertical axis indicates the number of pixels that have a corresponding gray scale value. By the histograms, we can get the distribution of gray scales of the input image.
According to the histograms, the first statistic unit 11A, the second statistic unit 11B, and the third statistic unit 11C can respectively find the maximum gray scales (Rmax, Gmax, Bmax) and the minimum gray scales (Rmin, Gmin, Bmin) corresponding to the red pixels, green pixels, and blue pixels. In some image processing methods in prior arts, the maximum gray scale is defined as the gray scale corresponding to the 0.5% area from the right of the histogram, while the minimum gray scale is defined as the gray scale corresponding to the 0.5% area from the left of the histogram.
Then, the gain generating module 12 selects the maximum one among the three maximum gray scales of the pixels as the maximum gray scale of the input image. Similarly, the minimum gray scale of the input image is the minimum one among the three minimum gray scales of the pixels. The traditional equation of image contrast stretching is:
                                          G            ″                    =                      255            ×                                          G                -                Min                                            Max                -                Min                                                    ,                            (                  Equation          ⁢                                          ⁢          1                )            
wherein G represents the original gray scale of some pixels, and G″ represents the stretched gray scale of the pixels.
Equation 1 can be rewritten into another form:G″=k×(G−Min)  (Equation 2)
wherein
                    k        =                              255                          Max              -              Min                                .                                    (                  Equation          ⁢                                          ⁢          3                )                            The value k in Equation 3 is generally called a contrast stretching coefficient or contrast gain.        
The gain generating module 12 first calculates the contrast gain (k) according to Equation 3 and sends the minimum gray scale (Min) and the contrast gain (k) to the contrast enhancing module 13. The contrast enhancing module 13 performs a contrast stretching calculation on each pixel of the input image according to Equation 2 and accordingly obtains the output image.
Taking the image shown in FIG. 3(A) as an example, the original maximum gray scale is 151, and the original minimum gray scale is 0 in this image. According to Equation 3, k is calculated to be 1.59, and the result of image contrast stretching is shown in FIG. 3(B). By comparison, we can find that the contrast of the image in FIG. 3(B) is much higher than that in FIG. 3(A).
The drawback of prior arts is that three statistic units are needed for calculating the individual distributions of the gray scales of the red pixels, green pixels, and blue pixels. Therefore the hardware resource is considerably consumed.